Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Connect to tenant database on channel join #677

Merged
merged 16 commits into from
Oct 12, 2023

Conversation

filipecabaco
Copy link
Contributor

@filipecabaco filipecabaco commented Sep 18, 2023

What kind of change does this PR introduce?

Before Realtime Channel join it checks if we're able to connect to Tenant database. If not we exit and avoid the client from connecting with the Channel.

Current procedure:

  • One running GenServer for each node in the node closest to the tenant
  • On GenServer init/1 check database connection with Postgrex and a SELECT 1 query
    • If successful, store in GenServer metadata the connection
    • If failed, GenServer dies
  • GenServer tracks shutdown of DBConnection process and dies, cleaning the :syn registry in the process

Notes:

  • Includes some refactors to
    • SynHandler made more reusable by allowing multiple modules
    • Realtime.Nodes made with common functions required for node management
    • Realtime.Helpers with extra functions for future refactors

Future Work

Later we will want to evolve this feature to a more solid health check of the tenant database connection.

@vercel
Copy link

vercel bot commented Sep 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
realtime-demo ⬜️ Ignored (Inspect) Visit Preview Oct 12, 2023 2:28pm

@filipecabaco filipecabaco force-pushed the feat/connect-tenant-on-join branch 14 times, most recently from c831d32 to ce7de8c Compare September 22, 2023 09:45
@filipecabaco filipecabaco marked this pull request as ready for review September 22, 2023 15:06
@filipecabaco filipecabaco force-pushed the feat/connect-tenant-on-join branch 3 times, most recently from 290a2db to d2a910d Compare September 22, 2023 16:53
@filipecabaco filipecabaco requested a review from a team September 22, 2023 17:17
@filipecabaco filipecabaco removed the request for review from a team September 22, 2023 17:45
@filipecabaco filipecabaco force-pushed the feat/connect-tenant-on-join branch 3 times, most recently from ffaaaf0 to d8a1636 Compare October 5, 2023 01:03
lib/realtime/tenants/check.ex Outdated Show resolved Hide resolved
@filipecabaco filipecabaco force-pushed the feat/connect-tenant-on-join branch from bf650bc to 11e4a79 Compare October 10, 2023 00:19
* GenServer only starts if able to connect to tenant database
* Process using :syn process registry with the connection as metadata
* DynamicSupervisor used to start GenServer
* DynamicSupervisor provided by a PartitionSupervisor
@filipecabaco filipecabaco force-pushed the feat/connect-tenant-on-join branch from 0f35569 to e1dc4d0 Compare October 11, 2023 21:28
@filipecabaco filipecabaco requested a review from a team October 11, 2023 23:34
lib/realtime/nodes.ex Outdated Show resolved Hide resolved
lib/realtime/nodes.ex Outdated Show resolved Hide resolved
Copy link

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Some comments added. :)

* Add tests to Realtime.Nodes
@filipecabaco filipecabaco merged commit 29152cb into main Oct 12, 2023
3 checks passed
@filipecabaco filipecabaco deleted the feat/connect-tenant-on-join branch October 12, 2023 15:50
@kiwicopple
Copy link
Member

🎉 This PR is included in version 2.25.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants